<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class CreateForumsTable extends Migration
{
	private $tableName = 'forums';
	private $tableComment = '店铺管理表';
	private $primaryKey = 'id';

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create($this->tableName, function (Blueprint $table) {
			$table->increments(env('DB_CONNECTION') == 'oracle' ? strtoupper($this->primaryKey) : $this->primaryKey)->comment('店铺id');
			$table->string('avatar', 100)->comment('头像图')->nullable();
            $table->unsignedInteger('uid')->comment('作者id');
			$table->string('title', 100)->comment('标题')->nullable();
			$table->string('des', 100)->comment('描述')->nullable();
			$table->string('nickname', 100)->comment('昵称')->nullable();
            $table->integer('is_recommend', false, true)->comment('置顶是否1是2否')->default(2);
            $table->integer('views',false, true)->comment('浏览量')->default(0);
            $table->integer('comment_num', false, true)->comment('评论数')->default(0);
            $table->integer('like_num', false, true)->comment('点赞数量')->default(0);
            $table->integer('status', false, true)->comment('商家是否审核通过1是0否')->default(0);
            $table->string('refund_msg', 100)->comment('拒绝原因')->nullable();
			$table->timestamps();
			if (env('DB_CONNECTION') == 'oracle') {
				$table->comment = $this->tableComment;
			}
		});

		if (env('DB_CONNECTION') == 'mysql') {
			DB::statement("ALTER TABLE `" . DB::getTablePrefix() . $this->tableName . "` comment '{$this->tableComment}'");
		}
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::dropIfExists($this->tableName);
		if (env('DB_CONNECTION') == 'oracle') {
			$sequence = DB::getSequence();
			$sequence->drop(strtoupper($this->tableName . '_' . $this->primaryKey . '_SEQ'));
		}
	}
}
